<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /*  Object.create()
       *创建一个对象
       *可以设置对象的__proto__属性(设置新对象是继承自哪一个对象)
       *可以给对象的每一个属性设置描述
       */

      //参数1查看
      const o = { name: "langwang" };
      const o1 = Object.create(null);
      console.log(o1);
      const o2 = Object.create(o);
      console.log(o2);

      //参数2查看
      const o3 = Object.create(null, {
        name: {
          value: "laowang", //属性值
          writable: false, //是否可写 默认是false
          enumerable: false, //是否可以枚举 默认是false
          configurable: false, //是否可以删除或者修改配置
        },
        age: {
          value: 18,
        },
      });

      //我们想要给对象添加属性,但是是可以描述的属性,必须使用Object.defineProperty方法
      Object.defineProperty(o3, "sex", {
        value: "男",
        writable: false,
        enumerable: false,
        configurable: false,
      });
      console.log(o3);

      //   存储器属性
      const o4 = Object.create(null, {
        firstName: {
          value: "lao",
          writable: true,
        },
        lastName: {
          value: "wang",
          writable: true,
        },
      });
      Object.defineProperty(o4, "fullName", {
        //getter函数
        get() {
          return this.firstName + " " + this.lastName;
        },
        //setter函数
        set(value) {
          console.log(value);
          const [firstName, lastname] = value.split(" ");
          this.firstName = firstName;
          this.lastName = lastname;
        },
      });

      console.log(o4.fullName);
      o4.fullName = "xiao li";
      console.log(o4);
    </script>
  </body>
</html>
